<template>
    <div class="box">
        <div class="pic">
            <img :src="item.imgUrl" alt="">
        </div>
        <div class="info">
            <div class="title">{{ item.name }}</div>
            <div class="wrapper">
                <div class="tag">
                    <i class="iconfont icon-tag"></i>
                    <span>{{item.discount}}折 限{{item.limitNum}}份</span>
                </div>
                <view class="price">
                    <div class="left">
                        <span class="normal">¥{{ item.newPrice }}</span>
                        <span class="through">¥{{ item.oldPrice }}</span>
                    </div>
                    <div class="btnwrapper">
                        <div class="mius" @click="minus(item)">-</div>
                        <div class="num">{{ item.num }}</div>
                        <div class="add" @click="buyGoods(item)">+</div>
                    </div>
                </view>
            </div>
        </div>
    </div>
</template>

<script setup>

import { useCartStore } from '@/store/module/cart';

const cartStore = useCartStore()

defineProps({
    item:{
        type:Object,
        default(){
            return {}
        }
    }
})

const buyGoods= (goods)=>{
    cartStore.buy(goods)
}

const minus=(goods) => {
    cartStore.minus(goods)
}
</script>

<style scoped lang="scss">
.box {
    display: flex;
    padding: 10px;

    .pic {
        width: 60px;
        height: 60px;
        border-radius: 3px;
        overflow: hidden;

        img{
            width: 100%;
            height: 100%;
        }
    }

    .info {
        padding: 0 15px 0 8px;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .title {
            font-size: 15px;
            color: #333;
            padding: 0;
        }

        .wrapper {

            .tag {
                margin: 10px 0;
                font-size: 11px;
                color: #F63747;

                .iconfont {
                    font-size: 11px;
                }
            }

            .price {
                display: flex;
                justify-content: space-between;
                align-items: center;

                .left {
                    .normal {
                        color: #F63747;
                        font-size: 15px;
                    }

                    .through {
                        text-decoration: line-through;
                        font-size: 11px;
                        color: #999;
                    }
                }

                .btnwrapper {
                    display: flex;
                    justify-content: space-around;
                    align-items: center;
                    color: #000;
                    bottom: 28px;
                    left: 0;

                    .mius {
                        width: 24px;
                        height: 24px;
                        border-radius: 50%;
                        border: 1px solid #2493F1;
                        color: #2493F1;
                        box-sizing: border-box;
                        text-align: center;
                        line-height: 24px;
                        font-size: 13px;
                    }

                    .num{
                        margin: 0 10px;
                    }

                    .add {
                        font-size: 13px;
                        width: 24px;
                        height: 24px;
                        text-align: center;
                        line-height: 24px;
                        background: #2493F1;
                        border-radius: 50%;
                        color: #fff;
                    }
                }
            }
        }
    }
}
</style>